package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.ParamsCommon;
import com.sumainfor.pc.market.dao.RdBankMapper;
import com.sumainfor.pc.market.dao.RdHousingSmartMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 智能门锁记录
 */
@Service
public class RdHousingSmartService implements Serializable {

    private ReentrantLock lock = new ReentrantLock(false);

    Logger log = LoggerFactory.getLogger(RdHousingSmartService.class);// 日志

    @Autowired
    private RdHousingSmartMapper rdHousingSmartMapper;

    /**
     * 查询需要删除智能设备id列表
     */
    public JsonResult getRdHouSmartDelIdList(Map<String,Object> params){
        JsonResult result=new JsonResult();
        Map<String,Object> resultMap=new HashMap<String,Object>();
        //智能设备供应商     0 无智能门锁   2.科技侠   3.果加
        String inteType="0";
        //保存需要删除的智能设备密码列表
        List<Map<String,Object>> list;
        if (params.get("ProOperaType")==null || params.get("HouId")==null || params.get("HouConId")==null
                || params.get("TenId")==null){
            return result.putFailed("参数不正确");
        }
        //租赁类型（1.合租 2.整租）
        if (params.get("ProOperaType").toString().equals("2")){
            params.put("IfHouId",1);//查询整套房源的智能密码编号
            list=rdHousingSmartMapper.getRdHouSmartDelIdList(params);
        }else{
            //先查询该租客在同房源租了几套房间
            Integer count=rdHousingSmartMapper.getRdHouSmartByTenHouIdList(params);
            if (count <= 1){//如果该租客在一套房源只租了一个房间那就把公共区域的钥匙一起删除
                params.put("IfCount",1);
            }
            params.put("IfHouConId",1);
            list=rdHousingSmartMapper.getRdHouSmartDelIdList(params);
        }
        if (list==null){
            list=new ArrayList<>();
        }
        for (Map<String,Object> map: list){
            if (map.get("SmaType")!=null){
                if (map.get("SmaType").toString().equals("2")){
                    inteType="2";
                }else if(map.get("SmaType").toString().equals("3")){
                    inteType="3";
                }
            }
        }
        resultMap.put("list",list);
        resultMap.put("inteType",inteType);
        return result.put(resultMap);
    }
}
